home *** CD-ROM | disk | FTP | other *** search
- /* $Id: ckmpri.c,v 1.5 91/12/15 23:17:46 rick Exp $
- * $Source: /uw/mackermit/RCS/ckmpri.c,v $
- *------------------------------------------------------------------
- * $Log: ckmpri.c,v $
- * Revision 1.5 91/12/15 23:17:46 rick
- * ut9
- *
- * Revision 1.4 91/10/13 13:44:33 rick
- * UT(7)
- *
- * Revision 1.3 91/10/03 12:43:06 rick
- * UT(5)
- *
- *------------------------------------------------------------------
- * $Endlog$
- */
-
- /*
- * file ckmpri.c
- *
- * Module of mackermit containing code for handling printing. This code was
- * originally put into ckmusr by John A. Oberschelp of Emory U.
- *
- */
-
- /*
- Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
- York. Permission is granted to any individual or institution to use this
- software as long as it is not sold for profit. This copyright notice must be
- retained. This software may not be included in commercial products without
- written permission of Columbia University.
- */
-
- #include "ckcdeb.h"
- #include "ckcker.h"
-
- #include "ckmdef.h" /* General Mac defs */
- #include "ckmres.h" /* Mac resource equates */
- #include "ckmasm.h" /* new A8 and A9 traps */
- #include "ckmcon.h" /* for fonts */
- #include "ckmptp.h" /* ckm* Prototypes */
-
-
- int to_printer = FALSE;
- int to_screen = TRUE;
- int printer_is_on_line_num;
- Handle hPrintBuffer = 0L;
- long lPrintBufferSize;
- long lPrintBufferChars;
- long lPrintBufferAt;
-
- extern MenuHandle menus[]; /* handle on our menus */
-
- DialogPtr printingDialog;
- DialogPtr bufferingDialog;
- DialogPtr overflowingDialog;
- DialogPtr overflowedDialog;
- DialogPtr pauseDialog;
-
- #define MIN(a,b) ((a)<(b))?(a):(b)
- #define MAX(a,b) ((a)>(b))?(a):(b)
-
- void
- now_print()
- {
- short itemhit;
- long index, length;
- /* CursHandle watchcurs; */
-
- if (lPrintBufferChars >= lPrintBufferSize) {
- overflowedDialog = GetNewDialog(OVERFLOWEDBOXID, NILPTR,
- (WindowPtr) - 1);
- circleOK(overflowedDialog);
-
- ModalDialog ((ModalFilterProcPtr) NILPROC, &itemhit);
- DisposDialog(overflowedDialog);
- if (itemhit == 2) /* if Cancel */
- return;
- if (itemhit == 3) {
- DisposHandle(hPrintBuffer);
- hPrintBuffer = 0L;
- lPrintBufferChars = 0L;
- updatepstat();
- return;
- }
- }
-
- if (lPrintBufferChars > lPrintBufferSize) { /* if buffer wrapped */
- length = lPrintBufferSize;
- index = lPrintBufferAt;
- } else {
- length = lPrintBufferChars;
- index = 0L;
- }
- printer(hPrintBuffer, length, index, lPrintBufferSize);
-
- DisposHandle(hPrintBuffer);
- hPrintBuffer = 0L;
- lPrintBufferChars = 0L;
- updatepstat();
- }
-
-
- /*
- * printer
- * h - handle to text to print
- * length - number of chars in buffer
- * index - starting index in buffer
- * limit - buffer limit (to wrap index)
- */
- printer (Handle h, long length, long index, long limit)
- {
- char PrintBufferChar;
- CursHandle watchcurs;
- int typeOfDriver;
- int chrExtra;
- int leftMargin;
- GrafPtr oldPort;
- int temp;
- TPPrPort myPrPort;
- THPrint PrintStuff;
- TPrStatus myStRec;
-
- PrintStuff = (THPrint)NewHandle(sizeof(TPrint));
- GetPort(&oldPort);
- PrOpen();
- if (PrError() == noErr) {
- temp = PrValidate(PrintStuff);
- temp = PrJobDialog(PrintStuff);
- if (!temp) {
- PrClose();
- SetPort(oldPort);
- return;
- }
- printingDialog = GetNewDialog(PRINTINGBOXID, NILPTR,
- (WindowPtr) - 1);
- DrawDialog (printingDialog);
- watchcurs = GetCursor(watchCursor);
- SetCursor(*watchcurs);
-
- myPrPort = PrOpenDoc(PrintStuff, nil, nil);
- typeOfDriver = ((*PrintStuff)->prStl.wDev) >> 8;
- if (typeOfDriver == 3) { /*laser*/
- TextFont(courier);
- TextSize(10);
- chrExtra = 0;
- leftMargin = 36;
- } else {
- TextFont(VT100FONT);
- TextSize(9);
- chrExtra = 1;
- leftMargin = 36;
- }
-
- printer_is_on_line_num = 1;
- PrOpenPage(myPrPort, nil);
- MoveTo(leftMargin, 1 * 12);
-
- do {
- if (PrError() != noErr)
- break;
- PrintBufferChar = (*h)[index];
- switch (PrintBufferChar) {
- case 13:
- if (++printer_is_on_line_num > 60) {
- PrClosePage(myPrPort);
- PrOpenPage(myPrPort, nil);
- printer_is_on_line_num = 1;
- }
- MoveTo(leftMargin, printer_is_on_line_num * 12);
- break;
-
- case 14:
- if (printer_is_on_line_num != 1) {
- PrClosePage(myPrPort);
- PrOpenPage(myPrPort, nil);
- printer_is_on_line_num = 1;
- }
- MoveTo(leftMargin, printer_is_on_line_num * 12);
- break;
-
- default:
- DrawChar(PrintBufferChar);
- Move(chrExtra, 0);
- break;
- }
-
- if (++index == limit) /* if time to wrap buffer */
- index = 0L;
-
- } while (--length);
- PrClosePage(myPrPort);
-
- PrCloseDoc(myPrPort);
- if ((PrError() == noErr) &&
- ((**PrintStuff).prJob.bJDocLoop == bSpoolLoop))
- PrPicFile(PrintStuff, nil, nil, nil, &myStRec);
- if ((PrError() != noErr) && (PrError() != 128)) {
- printerr ("Printer error: ", PrError());
- }
-
- DisposDialog(printingDialog);
- }
- PrClose();
- SetPort(oldPort);
- InitCursor();
- }
-
-
- void
- pr_stat()
- {
- DialogPtr printDialog;
- Str255 arg1, arg2, arg3;
- short itemhit;
-
-
- printDialog = GetNewDialog(PRINTBOXID, NILPTR, (WindowPtr) - 1);
- circleOK(printDialog);
-
- NumToString(MAX(lPrintBufferChars - lPrintBufferSize, 0L), arg1);
- NumToString(MIN(lPrintBufferSize, lPrintBufferChars), arg2);
- NumToString(lPrintBufferSize, arg3);
- ParamText (arg1, arg2, arg3, "");
-
- do {
- ModalDialog ((ModalFilterProcPtr) NILPROC, &itemhit);
-
- switch (itemhit) {
- case 1:
- case 2:
- case 3:
- break;
-
- }
- } while (itemhit > 3);
-
- DisposDialog(printDialog);
- }
-
-
- /*
- * Junk so Emacs will set local variables to be compatible with Mac/MPW.
- * Should be at end of file.
- *
- * Local Variables:
- * tab-width: 4
- * End:
- */
-